<?php
class Taxonomy_model extends CI_Model {
	function __construct() {
		parent::__construct();
	}
	
	// Lấy tất cả taxonomy
	function list_all($type, $order_by = $type.'_name', $order = 'ASC') {
		return $this->db->order_by($order_by, $order)
						->get($type)->result();
	}
	
	// Lấy taxonomy theo slug
	function get_by_slug($type, $taxonomy_slug) {
		return $this->db->where($type.'_slug', $taxonomy_slug)
						->get($type)->row();
	}
	
	// Lấy taxonomy theo id
	function get_by_id($type, $taxonomy_id) {
		return $this->db->where('id', $taxonomy_id)
						->get($type)->row();
	}
	
	// Lấy taxonomy theo post type id
	function list_all_by_post_type_id($type, $post_type, $post_type_id) {
		$this->db->select($post_type.'_'.$type.'.*, '.$post_type.'.'.$post_type.'_title, '.$post_type.'.'.$post_type.'_slug, '.$post_type.'.'.$post_type.'_description')
				->from($post_type.'_'.$type)
				->join($post_type, $post_type.'.id = ');
	}
}